package day05;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Demo04 {
    public static void main(String[] args) {
        /*
         * 定时任务线程池
         */
        ScheduledExecutorService timer =
                Executors.newScheduledThreadPool(3);
        //提交任务时候需要指定时间计划
        //TimeUnit: 时间单位
        // SECONDS 秒
        // delay: 延迟
        // Fixed: 固定
        // Rate: 频率
        timer.schedule(()-> System.out.println(Thread.currentThread()),
                1, TimeUnit.SECONDS);
        //已固定的频率执行
        timer.scheduleAtFixedRate(()-> System.out.println(Thread.currentThread()),
                1, 2, TimeUnit.SECONDS );
    }
}
